package com.abvnet.project.water.api.web;

import com.abvnet.framework.web.controller.BaseController;
import com.abvnet.framework.web.domain.AjaxResult;
import com.abvnet.project.water.project.domain.ProjectDataApi;
import com.abvnet.project.water.project.domain.ProjectLog;
import com.abvnet.project.water.project.domain.ProjectWater;
import com.abvnet.project.water.project.domain.WaterChart;
import com.abvnet.project.water.project.service.IProjectLogService;
import com.abvnet.project.water.project.service.IProjectWaterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
@RequestMapping("/api/project/data")
public class ApiProjectDataController extends BaseController {

    @Autowired
    private IProjectLogService projectLogService;
    @Autowired
    private IProjectWaterService projectWaterService;

    @GetMapping("/water")
    public AjaxResult water(ProjectLog projectLog) {
        WaterChart waterChart = projectLogService.selectProjectLogListForData(projectLog);
        ProjectWater waterStandard = projectWaterService.selectProjectWaterStandardByProjectId(projectLog.getProjectId());
        ProjectDataApi projectData = new ProjectDataApi();
        projectData.setWaterChart(waterChart);
        if (waterStandard != null) {
            if (waterStandard.getStandardCod() == null)
                waterStandard.setStandardCod(BigDecimal.valueOf(-1));
            if (waterStandard.getStandardNh3N() == null)
                waterStandard.setStandardNh3N(BigDecimal.valueOf(-1));
            if (waterStandard.getStandardTotalN() == null)
                waterStandard.setStandardTotalN(BigDecimal.valueOf(-1));
            if (waterStandard.getStandardTotalP() == null)
                waterStandard.setStandardTotalP(BigDecimal.valueOf(-1));
            if (waterStandard.getStandardPh() == null)
                waterStandard.setStandardPh(BigDecimal.valueOf(-1));
            if (waterStandard.getStandardDo() == null)
                waterStandard.setStandardDo(BigDecimal.valueOf(-1));
            if (waterStandard.getStandardT() == null)
                waterStandard.setStandardT(BigDecimal.valueOf(-1));
        } else {
            waterStandard = new ProjectWater();
            waterStandard.setStandardCod(BigDecimal.valueOf(-1));
            waterStandard.setStandardNh3N(BigDecimal.valueOf(-1));
            waterStandard.setStandardTotalN(BigDecimal.valueOf(-1));
            waterStandard.setStandardTotalP(BigDecimal.valueOf(-1));
            waterStandard.setStandardPh(BigDecimal.valueOf(-1));
            waterStandard.setStandardDo(BigDecimal.valueOf(-1));
            waterStandard.setStandardT(BigDecimal.valueOf(-1));
        }
        projectData.setWaterStandard(waterStandard);
        return AjaxResult.success(projectData);
    }

    @GetMapping("/micro")
    public AjaxResult micro(ProjectLog projectLog) {
        return AjaxResult.success(projectLogService.selectProjectLogMicroListForData(projectLog));
    }
}
